/**
 * author:Administrator
 * date:2013-5-21
 */
package com.roc.web.action.agent;

import java.util.ArrayList;
import java.util.List;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;
import com.roc.util.constant.Constant;

public class AgentSetSearchCondition extends BaseSearchCondition {
	

	private String orgCode;
	private String accountNo;
	private String realName;
	private String cardNo;
	private String mobile;
	private String status;       //代理商状态
	private String role;   //角色类型
	private long superId;
	private String agentType;//

	private String groupCd; // 商户类别，页面查询条件

	private String groupCdFlag; //受理市场标识
	
	private Object[] obj;

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getOrderPartOfHQL()
	 */
	@Override
	protected String getOrderPartOfHQL() {
		// TODO Auto-generated method stub
		
		return " ORDER BY o.dt_create ";
	}

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getRowCountHQL()
	 */
	@Override
	protected String getRowCountHQL() {
		
		StringBuffer hql = new StringBuffer(" select count(*) from T_OPERATORS o where o.ROLE_TYPE in('02','03')  ") ;

		// 如果登录账号不为系统管理员
		if(superId>0){
			// 查询当前登录账号下的直属代理商
			hql.append( " and ( o.SUPRI_ID = " + superId + "  ");
			// 如果查询角色是收单事业部
			if ( String.valueOf(superId).equals(Constant.SHOUDANSHIYEBU_ID) ){
				hql.append( " or o.oneagentid = o.id  ");
			}
			hql.append( " ) ");
		}
		return hql.toString();
	}

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getSearchHQL()
	 */
	@Override
	protected String getSearchHQL() {
		StringBuffer hql = new StringBuffer(" select   ");
		hql.append( " o.SUPRI_ID ,  " );	
		hql.append( " o.status ,  " );	
		hql.append( " o.account_No  ,  " );	
		hql.append( " o.id ,  " );	
		hql.append( " o.real_Name ,  " );	
		hql.append( " o.sex ,  " );	
		hql.append( " o.mobile ,  " );	
		hql.append( " o.ORG_CODE ,  " );	
		hql.append( " o.ROLE_TYPE ,  " );	
		hql.append( " o.card_No ,  " );	
		hql.append( " to_char( o.dt_Create ,'yyyy-MM-dd HH24:mi:ssxff6') , " );	
		hql.append( " to_char( o.dt_lastmod ,'yyyy-MM-dd HH24:mi:ssxff6') , " );	
		hql.append( " o.tax_registration_certificate , " );	
		hql.append( " o.organization_code , " );	

		hql.append( "    (select T1.Real_Name " );	
	    hql.append( "       from T_OPERATORS T1 " );	
	    hql.append( "      where T1.ROLE_TYPE in ( '00', '02','03') " );	
	    hql.append( "        and T1.id = o.supri_id) supri_name, " );	
	    hql.append( "    (select T2.Ins_Name " );	
	    hql.append( "       from tbl_ins_inf T2 " );	
	    hql.append( "      where T2.ins_type = '1' " );	
	    hql.append( "        and T2.Ins_Id_Cd = o.org_code) org_name " );	
	    
		hql.append( " from T_OPERATORS o where o.ROLE_TYPE in('02','03')  ");


		// 如果登录账号不为系统管理员
		if(superId>0){
			// 查询当前登录账号下的直属代理商
			hql.append( " and ( o.SUPRI_ID = " + superId + "  ");
			// 如果查询角色是收单事业部
			if ( String.valueOf(superId).equals(Constant.SHOUDANSHIYEBU_ID) ){
				hql.append( " or o.oneagentid = o.id  ");
			}
			hql.append( " ) ");
		}
		
		return hql.toString();
	}

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getWhereHQLFieldBeanList()
	 */
	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {
		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();


		
		if (Constance.isNotEmpty(orgCode)) {
			filedBeanList.add(new WhereHQLFieldBean("o.org_code", orgCode.trim(), "=", false));
		}
		
		if (Constance.isNotEmpty(accountNo)) {
			filedBeanList.add(new WhereHQLFieldBean("o.account_no", accountNo.trim(), "=", false));
		}

		if (Constance.isNotEmpty(realName)) {
			filedBeanList.add(new WhereHQLFieldBean("o.real_name", realName.trim(),
					"LIKE", false, "ALL"));
		}
		if (Constance.isNotEmpty(mobile)) {
			filedBeanList.add(new WhereHQLFieldBean("o.mobile", mobile.trim(), "=", false));
		}
		if (Constance.isNotEmpty(cardNo)) {
			filedBeanList.add(new WhereHQLFieldBean("o.card_no", cardNo.trim(), "=", false));
		}
		if(Constance.isNotEmpty(agentType)&&!"99".equals(agentType)){
			filedBeanList.add(new WhereHQLFieldBean("o.agent_type", agentType.trim(), "=", false));
		}
		if (Constance.isNotEmpty(groupCd)) {
			filedBeanList.add(new WhereHQLFieldBean("o.GROUP_CD", new Long(groupCd.trim()), "=", false));
		}
		if (Constance.isNotEmpty(groupCdFlag)) {
			filedBeanList.add(new WhereHQLFieldBean("o.GROUP_CD", new Long(groupCdFlag.trim()), "=", false));
		}
		
/*
		if(superId>0){
			filedBeanList.add(new WhereHQLFieldBean("o.SUPRI_ID", superId, "=", false));
		}*/
		
		
		
		
		return filedBeanList;
	}

	/**
	 * @return the accountNo
	 */
	public String getAccountNo() {
		return accountNo;
	}

	/**
	 * @param accountNo the accountNo to set
	 */
	public void setAccountNo(String accountNo) {
		this.accountNo = accountNo;
	}

	/**
	 * @return the realName
	 */
	public String getRealName() {
		return realName;
	}

	/**
	 * @param realName the realName to set
	 */
	public void setRealName(String realName) {
		this.realName = realName;
	}

	/**
	 * @return the cardNo
	 */
	public String getCardNo() {
		return cardNo;
	}

	/**
	 * @param cardNo the cardNo to set
	 */
	public void setCardNo(String cardNo) {
		this.cardNo = cardNo;
	}

	public String getOrgCode() {
		return orgCode;
	}

	public void setOrgCode(String orgCode) {
		this.orgCode = orgCode;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getRole() {
		return role;
	}

	public void setRole(String role) {
		this.role = role;
	}

	

	public Object[] getObj() {
		return obj;
	}

	public void setObj(Object[] obj) {
		this.obj = obj;
	}

	public long getSuperId() {
		return superId;
	}

	public void setSuperId(long superId) {
		this.superId = superId;
	}

	public String getAgentType() {
		return agentType;
	}

	public void setAgentType(String agentType) {
		this.agentType = agentType;
	}

	public String getGroupCd() {
		return groupCd;
	}

	public void setGroupCd(String groupCd) {
		this.groupCd = groupCd;
	}

	public String getGroupCdFlag() {
		return groupCdFlag;
	}

	public void setGroupCdFlag(String groupCdFlag) {
		this.groupCdFlag = groupCdFlag;
	}

}
